
const button = document.querySelector(".button");
const username = document.querySelector(".username input");
const password = document.querySelector(".password input");
console.log(username,password,button)


button.onclick = function(){
    ajaxPost("http://localhost:3000/api",res=>{
        console.log(res)
        res = JSON.parse(res);
        if(res.code===0){
            alert("密码错误，请重新输入");
            password.value="";
            password.focus();
        }else if(res.code===1){
            if(confirm("登录成功，是否跳转到首页")){
                location.href = "./index.html"
            }
            localStorage.setItem("isLogin","OK")
            localStorage.setItem("username",res.data)

        }else if(res.code===2){
            if(confirm("用户名不存在，是否跳转到注册页面")){
                location.href = "./register.html"
            }else{
                username.value="";
                username.focus();
            }
        }
    },
    {
        type:"login",
        username:username.value,
        password:password.value,

    })
}